home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
c
/
btnc200
/
logfile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-30
|
4KB
|
245 lines
/*------------------------------------------------
//
// Module: module logfile.c
//
// Objet : Gestion de fichier traceur type 'logfile'
//
// ToDo :
//
//
//
// Maintenance :
//
// Auteur : Olivier Booklage
// Version : V1.1
// Date : 05/05/1996
// Remarq. : On peut optimiser..
//
// Source pour PURE-C / Sozobon 2.02 eXtended version
//-----------------------------------------------*/
/* --- Includes externes -- */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#include <aes.h>
#include "portab.h"
/* --- Includes internes -- */
/* --- Constantes globales internes --- */
/* --- Structures globales internes --- */
/* --- Variables globales internes --- */
static FILE *logfile=NULL;
static char flag_logfile_opened=FALSE;
static char logfilename[128];
WORD ret;
/* --- Prototypage extern --- */
BOOLEAN logfile_open( char *file );
WORD STD_printf(char *fmt,...);
WORD ALL_printf(char *fmt,...);
WORD LOG_printf(char *fmt,...);
WORD ERR_printf(char *fmt,...);
WORD STD_puts(char *string);
WORD ALL_puts(char *string);
WORD LOG_puts(char *string);
WORD ERR_puts(char *string);
BOOLEAN logfile_close(void);
VOID write_disk_error(char *message);
VOID read_disk_error(char *message);
/* --- Prototypage interne --- */
/* --- Fonctions ----*/
BOOLEAN logfile_open( char *file )
{
if (flag_logfile_opened==TRUE) return(FALSE);
logfile = fopen( file ,"w");
if ( logfile == NULL) return(FALSE);
setvbuf(logfile,NULL,_IOFBF,32*1024L);
flag_logfile_opened=TRUE;
strcpy(logfilename,file);
return(TRUE);
}
/*-------------------------------*/
WORD STD_printf(char *fmt,...)
{
va_list args;
va_start(args,fmt);
ret=vfprintf(stdout,fmt,args);
va_end(args);
return(ret);
}
/*-------------------------------*/
WORD ALL_printf(char *fmt,...)
{
va_list args;
va_start(args,fmt);
vfprintf(stdout,fmt,args);
va_end(args);
if (flag_logfile_opened!=TRUE) return(0);
va_start(args,fmt);
vfprintf(logfile,fmt,args);
va_end(args);
ret=fflush(logfile);
if( ret==EOF ) write_disk_error("Logfile");
return(ret);
}
/*-------------------------------*/
WORD ERR_printf(char *fmt,...)
{
va_list args;
/* printf */
va_start(args,fmt);
vfprintf(stderr,fmt,args);
va_end(args);
/* logfile */
if (flag_logfile_opened!=TRUE) return(0);
va_start(args,fmt);
vfprintf(logfile,fmt,args);
va_end(args);
ret=fflush(logfile);
if( ret==EOF ) write_disk_error("Logfile");
return(ret);
}
/*-------------------------------*/
WORD LOG_printf(char *fmt,...)
{
va_list args;
if (flag_logfile_opened!=TRUE) return(0);
va_start(args,fmt);
vfprintf(logfile,fmt,args);
va_end(args);
ret=fflush(logfile);
if( ret==EOF ) write_disk_error("Logfile");
return(ret);
}
/*-------------------------------*/
WORD STD_puts( char *string)
{
ret=fputs(string,stdout);
return(ret);
}
/*-------------------------------*/
WORD LOG_puts( char *string )
{
if (flag_logfile_opened==FALSE) return(0);
fputs(string,logfile);
ret=fflush(logfile);
if( ret==EOF ) write_disk_error("Logfile");
return(ret);
}
/*-------------------------------*/
WORD ALL_puts( char *string)
{
STD_puts( string );
ret=LOG_puts( string );
return( ret );
}
/*-------------------------------*/
WORD ERR_puts( char *string)
{
/* puts */
fputs(string,stderr);
if (flag_logfile_opened==FALSE) return(0);
/* logfile */
fputs(string,logfile);
ret=fflush(logfile);
if( ret==EOF ) write_disk_error("logfile");
return(ret);
}
/*-------------------------------*/
BOOLEAN logfile_close(void)
{
if (flag_logfile_opened==FALSE) return(FALSE);
fclose(logfile);
flag_logfile_opened=FALSE;
return(TRUE);
}
VOID write_disk_error(char *message)
{
char i;
fprintf(stderr,"\n\n** DISK WRITE ERROR on %s **\n",message);
for(i=0;i<10;i++)
{
fputs("\a",stderr);
evnt_timer(1000,0);
}
exit(1);
}
VOID read_disk_error(char *message)
{
char i;
fprintf(stderr,"\n\n** DISK READ ERROR on %s **\n",message);
for(i=0;i<10;i++)
{
fputs("\a",stderr);
evnt_timer(1000,0);
}
exit(1);
}
/* --- EOF --- */